package Metier;

import java.util.ArrayList;


public class SimMap {
	private int _height;
	private int _width;
	private ArrayList<Obstacle> _listObstacle ;
	private int _scale;
	
	public SimMap(int width, int height){
		_height = height;
		_width = width;
		_listObstacle = new ArrayList<Obstacle>();
		_scale = this.getHeight()/2 + this.getWidth()/2;
	}
	
	public int getWidth() {
		return _width;
	}
	
	public int getHeight() {
		return _height;
	}
	
	public void addObstacle(Obstacle obst) {
		_listObstacle.add(obst);
	}
	
	public boolean isInMap(int posX, int posY){
		if (posX /_scale < 0 || posY < 0)
			return false;
		if (posX / _scale > _height || posY > _width)
			return false;
		for (Obstacle obs : _listObstacle){
			if(isInObstacle(obs,posX,posY)) return false;
		}
		return true;
	}
	
	private boolean isInObstacle(Obstacle obs, int posX, int posY){
		if(posX > obs.get_positionLeftUpCorner()[0] &&
		   posX < obs.get_positionLeftUpCorner()[0]+obs.get_dimension()[0]){
			if(posY > obs.get_positionLeftUpCorner()[1] &&
			   posY < obs.get_positionLeftUpCorner()[1]+obs.get_dimension()[1]){
				return true;
			} 
			else 
				return false;				
		}
		else
			return false;
	}
	
	// return a table of two int with the X and Y limits
	public int getLimits(int posX, int posY){
		return 0;
	}

	public int getScale() {
		return _scale;
	}
}
